package  com.hadron.media.slideshow.data
{
	import temple.data.loader.preload.IPreloader;
	/**
	 * Created On: 2011-03-09 08:26 
	 * @author Hadron
	 * 
	 * 
	 * Can be used instead of a generic Object to define the <code>vars</code>
	 * parameter of a Slideshow's constructor.
	 */
	public class SlideshowVars
	{
		/** @private **/
		protected var _vars:Object;
		
		/**
		 * @param	vars A generic Object containing
		 * properties that you'd like to add to this SlideshowVars instance.
		 */
		public function SlideshowVars(vars:Object = null)
		{
			_vars = { };
			if (vars != null) 
			{
				for (var p:String in vars) 
				{
					_vars[p] = vars[p];
				}
			}
		}
		
		/*----------------------- PROTECTED  METHODS -------------------------*/
		protected function _set(property:String, value:*):SlideshowVars 
		{
			if (value == null) 
			{
				delete _vars[property]; //in case it was previously set
			}
			else 
			{
				_vars[property] = value;
			}
			return this;
		}
		
		/* -------------------------- PUBLIC METHODS ------------------------*/
		/**
		 * @param	value When autoPlay is true - slideshow begins playing automatically 
		 * after finishing loading contents without calling start() method externally.
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function autoPlay(value:Boolean):SlideshowVars
		{
			return _set("autoPlay", value);
		}
		/**
		 * @param	value When autoLoad is true - slideshow begins loading items automatically 
		 * after setting data array. Otherwise you're obliged to use loadItems() method
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function autoLoad(value:Boolean):SlideshowVars
		{
			return _set("autoLoad", value);
		}
		/**
		 * @param	value Sets array of urls to load
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function data(value:Array):SlideshowVars
		{
			return _set("data", value);
		}
		/**
		 * @param	value DisplayTime of each item - float number
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function displayTime(value:Number):SlideshowVars
		{
			return _set("displayTime", value);
		}
		/**
		 * @param	value FadeTime of each item - float number
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function fadeTime(value:Number):SlideshowVars
		{
			return _set("fadeTime", value);
		}
		/**
		 * @param	value CurrentIndex of displayed item.
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function curIndex(value:uint):SlideshowVars
		{
			return _set("curIndex", value);
		}
		/**
		 * @param	value When set to true - enables debug mode of the component.
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function debug(value:Boolean):SlideshowVars
		{
			return _set("debug", value);
		}
		/**
		 * @param	value Sets preloader for Slideshow component
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function preloader(value:IPreloader):SlideshowVars
		{
			return _set("preloader", value);
		}
		/**
		 * @param	value indicates whether to display background at the bottom layer of slideshow
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function background(value:Boolean):SlideshowVars
		{
			return _set("background", value);
		}
		/**
		 * @param	value value of slideshow background opacity
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function backgroundAlpha(value:Number):SlideshowVars
		{
			return _set("backgroundAlpha", value);
		}
		/**
		 * @param	value hex value of slideshow background color
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function backgroundColor(value:uint):SlideshowVars
		{
			return _set("backgroundColor", value);
		}
		/**
		 * @param	value path to xml file containing settings node (optional)
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function xmlURL(value:String):SlideshowVars
		{
			return _set("xmlURL", value);
		}
		//event handler functions
		/**
		 * @param	value Handler for SlideshowEvent.ITEMS_LOAD_COMPLETE events 
		 * which is dispatched when slideshow completes loading its loading process
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function onItemsLoadComplete(value:Function):SlideshowVars
		{
			return _set("onItemsLoadComplete", value);
		}
		/**
		 * @param	value Handler function for SlideshowEvent.ITEM_OUT_COMPLETE events
		 * which are dispatched each time slideshow completes its transitionOut of current slideshowItem
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function onItemInComplete(value:Function):SlideshowVars
		{
			return _set("onItemInComplete", value);
		}
		/**
		 * @param	value Handler function for SlideshowEvent.ITEM_OUT_COMPLETE events
		 * which are dispatched each time slideshow completes its transitionOut of current slideshowItem
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function onItemOutComplete(value:Function):SlideshowVars
		{
			return _set("onItemOutComplete", value);
		}
		/**
		 * @param	value Handler function for SlideshowEvent.ITEM_CHANGE events
		 * which are dispatched each time slideshow changes its current item
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function onItemChange(value:Function):SlideshowVars
		{
			return _set("onItemChange", value);
		}
		/**
		 * @param	value Handler function for SlideshowEvent.ERROR events
		 * dispatched e.g. when slideshow <code>start</code> method was called before loading finished
		 * or array of assets to load wasn't set.
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function onError(value:Function):SlideshowVars
		{
			return _set("onError", value);
		}
		/**
		 * @param	value Handler function for temple.status.StatusEvent.STATUS_CHANGE events
		 * which are dispatched each time slideshow changes its status
		 * @return SlideshowVars instance useful with chain functions
		 */
		public function onStatusChange(value:Function):SlideshowVars
		{
			return _set("onStatusChange", value);
		}
		
		/* --------------------------------------GETTERS / SETTERS --------------------------------------*/
		/** 
		 * The generic Object populated by all of the method calls in the SlideshowVars instance.
		 * This is the raw data that gets passed to the loader.
		 */
		public function get vars():Object { return _vars; }
		/** @private */
		public function get isSlideshowVars():Boolean { return true; }
	}
}